package com.medusa.aps.business.modules.demand.model.output;

import com.medusa.aps.business.model.enums.SchedulingStatusEnum;
import com.medusa.aps.business.util.PercentageScheduleUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author miskw
 * @date 2024/1/6
 */
@Data
public class ScheduleDetailSelfModel {
    @Schema(description = "订单号")
    private String orderNumber;
    @Schema(description = "物料编码")
    private String materialCode;
    @Schema(description = "物料名称")
    private String materialName;
    @Schema(description = "排产状态")
    private SchedulingStatusEnum schedulingStatus;
    @Schema(description = "需求数量")
    private Integer demandQuantity;
    @Schema(description = "计划数量")
    private Integer plannedQuantity;
    @Schema(description = "已完工数量")
    private Integer completedQuantity;
    @Schema(description = "未完工数量")
    private Integer unfinishedQuantity;
    @Schema(description = "加工进度")
    private BigDecimal orderProgress;
    @Schema(description = "计划开始时间")
    private LocalDateTime plannedStartTime;
    @Schema(description = "计划结束时间")
    private LocalDateTime plannedEndTime;
    @Schema(description = "实际完工时间")
    private LocalDateTime actualCompletionTime;

    public String getOrderProgress() {
        if (this.getSchedulingStatus() == SchedulingStatusEnum.CLOSE) {
            return "100.00%";
        } else {
            return PercentageScheduleUtils.decimalConvertPercentage(orderProgress);
        }
    }

    public Integer getCompletedQuantity() {
        if (this.getSchedulingStatus() == SchedulingStatusEnum.CLOSE) {
            return this.plannedQuantity;
        } else {
            return this.completedQuantity;
        }
    }
}
